package com.zbkj.crmeb.supplier.controller;

import java.util.Arrays;
import java.util.Map;

// import org.apache.shiro.authz.annotation.RequiresPermissions;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.crmeb.core.exception.CrmebException;
import com.github.pagehelper.PageInfo;
import com.zbkj.crmeb.store.request.SupplierOpenShopProductRequest;
import com.zbkj.crmeb.store.response.SupplierOpenShopProductResponse;
import com.zbkj.crmeb.supplier.model.SupplierOpenShopProduct;
import com.zbkj.crmeb.supplier.service.SupplierOpenShopProductService;


/**
 * 供应商一键开店中的商品表
 *
 * @author lss
 * @email didiok@foxmail.com
 * @date 2024-11-18 17:36:49
 */
@Slf4j
@RestController
@RequestMapping("supplier/supplier/open/shop/product")
public class SupplierOpenShopProductController {
    @Autowired
    private SupplierOpenShopProductService supplierOpenShopProductService;

    /**
     * 分页显示注册申请
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     */
    @ApiOperation(value = "一进开店分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<SupplierOpenShopProductResponse>> getList(@Validated SupplierOpenShopProductRequest request, @Validated PageParamRequest pageParamRequest) {
        PageInfo<SupplierOpenShopProductResponse> pageInfo = new PageInfo<>();
        try {
            pageInfo = supplierOpenShopProductService.getList(request, pageParamRequest);
        }catch (Exception e){
            log.error("一进开店商品查询报错，", e);
            throw new CrmebException("一进开店商品查询报错");
        }
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    /**
     * 查询注册申请信息
     * @param id Integer
     * @author Mr.Zhang
     * @since 2020-05-27
     */
    @ApiOperation(value = "详情")
    @GetMapping("/info/{id}")
    public CommonResult<SupplierOpenShopProduct> info(@PathVariable Integer id) {
        SupplierOpenShopProduct supplierOpenShopProduct = new SupplierOpenShopProduct();
        try {
            supplierOpenShopProduct = supplierOpenShopProductService.getById(id);
        }catch (Exception e){
            log.error("一进开店信息查询报错，", e);
            throw new CrmebException("一进开店信息查询报错");
        }

        return CommonResult.success(supplierOpenShopProduct);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete/{id}")
    public CommonResult<String> delete(@PathVariable Integer id) {
        boolean b = false;
        try{
            b = supplierOpenShopProductService.removeById(id);
        }catch (Exception e){
            log.error("一进开店商品删除报错，", e);
            throw new CrmebException("一进开店商品删除报错");
        }
        return b ? CommonResult.success() : CommonResult.failed();
    }

}
